package com.lry.basic.aop.cglib.interfaces;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

public class UserMapperInterceptor implements MethodInterceptor {

    /**
     *
     * @param proxy 代理对象
     * @param method 目标方法
     * @param args 目标方法参数
     * @param methodProxy 代理方法
     * @return
     * @throws Throwable
     */
    @Override
    public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {

        Annotation[] annos = method.getAnnotations();
        for(Annotation anno:annos){
            if(anno instanceof Select){
                Select as = (Select) anno;
                System.out.println(method.getName()+" 执行sql:"+as.value());
            }
        }
        int seleteFromSql = 100;

        return seleteFromSql;

    }

}
